<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>

</head>
<body>
<input type="text" id="message">
<input type="submit" id="button">
</body>
<script>
    let message = document.getElementById("message");
    let webSocket = new WebSocket("ws://127.0.0.1:8080/test");
    let button = document.getElementById("button");
    button.onclick = function () {
        webSocket.send(message.value)
    }

    webSocket.onopen = function () {
        console.log("建立连接")
    }
    webSocket.onmessage = function (e) {
        console.log(e.data);
    }
    webSocket.onerror = function () {
        console.log("连接异常");
    }
    webSocket.onclose = function () {
        console.log("连接关闭");
    }


</script>
</html>